#include <stdio.h>

int main(int argc, char **argv)
{
    FILE *fp;
    char s[1024]; // 数组必须足够大，足以放下一行
    int linecount = 0;

    fp = fopen("data.txt", "r");
    if (fp == NULL)
    {
        printf("open file error\n");
        return -1;
    }

    while (fgets(s, sizeof s, fp) != NULL)
        printf("%d: %s", ++linecount, s);
    printf("\n");

    int closed = fclose(fp);
    if (closed != 0)
    {
        printf("close file error\n");
    }

    // fputs int fputs(const char* str, FILE* stream);
    char words[14];

    puts("Enter a string, please.");
    fgets(words, 14, stdin);

    puts("This is your string:");
    fputs(words, stdout);
    return 0;
}